﻿using System;
using System.Reflection;

namespace Moonlite.Data.Configuration
{
    /// <summary>
    /// Provides helper methods for getting types from strings.
    /// </summary>
    internal static class TypeGetHelpers
    {
        /// <summary>
        /// Gets the type from the given name.
        /// </summary>
        /// <param name="fullname">The fullname.</param>
        /// <returns>The found type.</returns>
        public static Type GetTypeFromFullName(string fullname)
        {
            if (string.IsNullOrEmpty(fullname))
            {
                throw new ArgumentNullException("fullname");
            }

            AppDomain currentDomain = AppDomain.CurrentDomain;
            foreach (Assembly assembly in currentDomain.GetAssemblies())
            {
                Type testType = assembly.GetType(fullname);
                if (testType != null)
                {
                    return testType;
                }
            }

            return null;
        }
    }
}
